Comparison
Example (Step 3)
if (amountRequested < accountBalance)
{
withdraw(amountRequested);
} else {
withdraw(0);
notifyCustomer();
}
Automated teller machine.
A customer makes a request for a certain amount of cash, and your responsibility is to determine if they should be allowed to withdraw that amount.
Problem solving sequence:
1.Algorithm
2.Pseudo-code
3.C code
You'll notice some new syntax in this example, but don't worry about it too much. Pay close attention to the very first line, which checks to make sure that the amount requested is less than the account balance. The way it works is, if the expression between parentheses (()) evaluates to true, then the first block of code will be read. That is, the code inside the first set of curly braces ({}) will be executed. If the expression in parentheses evaluates to false, on the other hand, then the second block of code (the code following the word else) will be read. In this case, the first block of code withdraws the amount requested by the customer, while the second block of code withdraws nothing, and notifies the customer.